/**
 * 酸式滴定管
 */
Didingguan = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_DDG_DDG);
	},
	init:function(){
		this.body = new Button(this, 10, TAG_DDG, "#ddg_left.png", this.callback);	
		
		var hand = new Button(this, 9, TAG_LEFT, "#hand_left.png", this.callback);
		hand.setPosition(cc.p(-32,170));
		var part = new Button(this, 11, TAG_LEFT_PART, "#hand_left_part.png", this.callback);
		part.setPosition(cc.p(-32,170));
		// 水位线
		var line = new cc.Sprite("#cyl.png");
		line.setOpacity(255);
		line.setPosition(24, this.body.height*0.2 );
		line.setScale(0.7);
		this.body.addChild(line, 12, TAG_DDG_LINE);
		//活塞
		var huosai = new Button(this.body, 13, TAG_HUOSAI, "#ddg_huosai2.png",this.callback,this);
		huosai.setPosition(this.width +41, 60 );
		//活塞手内侧
		var huo_hand=new cc.Sprite("#huosai_hand.png");
		huo_hand.setPosition(cc.p(-51,-197));
		this.addChild(huo_hand, 1,TAG_HUO_HAND);
		huo_hand.setVisible(false);
		//活塞手外侧
		var huo_hand_part=new cc.Sprite("#huosai_hand_part.png");
		huo_hand_part.setPosition(cc.p(-51,-197));
		this.addChild(huo_hand_part, 50,TAG_HUO_HAND_PART);
		huo_hand_part.setVisible(false);
			
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	loadHand:function(){
		var body=this.getChildByTag(TAG_DDG);
		var hand1=new cc.Sprite("#hand1.png");
		body.addChild(hand1,5);
		hand1.setPosition(cc.p(this.width-70,55));
		var seq=cc.sequence(cc.delayTime(2),cc.callFunc(function() {
			hand1.removeFromParent();
		}, this));
		hand1.runAction(seq);
	},
	// 水位线上升
	lineUp:function(pos){
		var line = this.getChildByTag(TAG_DDG).getChildByTag(TAG_DDG_LINE);
		var show = cc.fadeTo(0.5,255);
		var move = cc.moveBy(1.5,pos);
		var seq = null;
			seq = cc.sequence(show, move);
		line.runAction(seq);
	},
	// 水位线下降
	lineDown:function(pos){
		var line = this.getChildByTag(TAG_DDG).getChildByTag(TAG_DDG_LINE);
		var move = cc.moveTo(1.5,pos);
		var seq = null;
			seq = cc.sequence(move);
		line.runAction(seq);
	},
	//滴定水滴
	loadPoint:function(){
		var point=new cc.Sprite("#wpoint.png");
		point.setScale(0.5);
		var move=cc.moveTo(0.6, cc.p(5,-360));
		var seq=cc.sequence(move,cc.callFunc(function() {
			point.removeFromParent();
		}, this));
		point.runAction(seq);
		point.setPosition(cc.p(5,-262));
		this.addChild(point);
	},
	//横向转动清洗动画
	ddgClean:function(){
		var hand = new Button(this, 9, TAG_RIGHT, "#hand_right.png", this.callback);
		hand.setPosition(cc.p(-45,-95));
		hand.setRotation(140);
		var part = new Button(this, 11, TAG_RIGHT_PART, "#hand_right_part.png", this.callback);
		part.setPosition(cc.p(-45,-95));
		part.setRotation(140);
		
		var ddg = new cc.Sprite("#ddg/ddg_1.png");
		ddg.setPosition(10, 0);
		ddg.setRotation(-90);
		this.addChild(ddg, 10, TAG_DDG_CLEAN);

		var animFrames = [];
		for (var i = 1; i < 6; i++) {
			var str = "ddg/ddg_" + i + ".png";
			var frame = cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation = new cc.Animation(animFrames, 0.1,2);
		var action = cc.animate(animation);
		var seq=cc.sequence(action,cc.callFunc(function() {
			ddg.removeFromParent();
			hand.removeFromParent();
			part.removeFromParent();
		}, this));
		ddg.runAction(seq);

	},
	callback:function(p){
		var func = cc.callFunc(this.actionDone, this);
		var line = this.getChildByTag(TAG_DDG).getChildByTag(TAG_DDG_LINE);
		var beaker=this.getParent().getChildByTag(TAG_BEAKER);
		var action=gg.flow.flow.action;
		var hand=this.getChildByTag(TAG_LEFT);				
		var part=this.getChildByTag(TAG_LEFT_PART);
		switch(p.getTag()){
		case TAG_DDG:
			if(action==ACTION_DO1){
			var move = cc.moveTo(0.6,cc.p(168,410));
			var seq = cc.sequence(move,cc.callFunc(function(){
				hand.setVisible(false);
				part.setVisible(false);
				
				var blue=new cc.Sprite("#33.png");
				blue.setPosition(cc.p(8,-25));
				blue.setScaleY(1.3);
				this.addChild(blue,21,TAG_BLUE);
				blue.setOpacity(255);
				
				this.getParent().clock.loadTip("#tool/tip1.png");
				this.getParent().clock.doTime(2);
				this.lineUp(cc.p(0,3));
			},this),this.callNext);
			this.runAction(seq);
			}else if(action==ACTION_DO2){
				var move=cc.moveTo(0.6, cc.p(820,362));
				var seq=cc.sequence(move,this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO3){
				var rot=cc.rotateTo(0.6, -90);
				var rot1=cc.rotateTo(0.6, 0);
				var move=cc.moveTo(0.6, cc.p(820,362));
				var fadeout=cc.fadeOut(0);
				var fadein=cc.fadeIn(0);
				var seq=cc.sequence(rot,cc.callFunc(function() {
					hand.runAction(cc.spawn(cc.moveTo(0.2,cc.p(-45,170)),cc.rotateTo(0.2, 45)));
					part.runAction(cc.spawn(cc.moveTo(0.2,cc.p(-45,170)),cc.rotateTo(0.2, 45)));
					p.runAction(cc.fadeOut(0));
				}, this),cc.callFunc(function() {
					this.ddgClean();
				}, this),cc.delayTime(1),cc.callFunc(function() {
					hand.runAction(cc.spawn(cc.moveTo(0.2,cc.p(-32,170)),cc.rotateTo(0.2, 0)));
					part.runAction(cc.spawn(cc.moveTo(0.2,cc.p(-32,170)),cc.rotateTo(0.2, 0)));
					p.runAction(cc.fadeIn(0));			
				}, this),cc.delayTime(0.2),rot1,move,this.callNext);
				this.runAction(seq);
				
				var sca=cc.scaleTo(0.6, 0.1,35);	
				var sca1=cc.scaleTo(0.6, 0.6);
				var seq1=cc.sequence(sca,cc.delayTime(1),sca1);
				line.runAction(seq1);
			}else if(action==ACTION_DO4){
				if(this.getChildByTag(TAG_BLUE)!=null){
					this.getChildByTag(TAG_BLUE).removeFromParent();
				}
				hand.setVisible(true);
				part.setVisible(true);
				var move=cc.moveTo(0.6, cc.p(820,362));
				var seq=cc.sequence(move,this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO5){
				
			}else if(action==ACTION_DO6){
				var move = cc.moveTo(0.6,cc.p(168,456));
				var seq = cc.sequence(move,cc.callFunc(function() {
					var blue=new cc.Sprite("#33.png");
					blue.setPosition(cc.p(8,-91));
					blue.setScaleY(1.3);
					this.addChild(blue,21,TAG_BLUE);
//					blue.setOpacity(255);
					
					hand.setVisible(false);
					part.setVisible(false);
				}, this),this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO7){
//显示读数		
				if(this.getChildByTag(TAG_BLUE)!=null){
					this.getChildByTag(TAG_BLUE).setOpacity(0);
				}
				hand.setVisible(true);
				part.setVisible(true);
				var mov=cc.moveTo(0.6,cc.p(168,456));
				var move=cc.moveTo(0.6, cc.p(268,456));
				var seq=cc.sequence(move,cc.callFunc(function() {
					var p1=new cc.Sprite("#20ml.png");
					this.addChild(p1);
					p1.setPosition(cc.p(111,97));
					var seq=cc.sequence(cc.delayTime(1.5),cc.fadeOut(0));
					p1.runAction(seq);
				}, this),cc.delayTime(2),mov,cc.callFunc(function() {
					this.getChildByTag(TAG_BLUE).setOpacity(255);
					hand.setVisible(false);
					part.setVisible(false);
					var show=new ShowTip("记录数据，V1=20.0ml" ,cc.p(650,350));
				}, this),cc.delayTime(1),this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO8){
//显示读数			
				if(this.getChildByTag(TAG_BLUE)!=null){
					this.getChildByTag(TAG_BLUE).setOpacity(0);
				}
				hand.setVisible(true);
				part.setVisible(true);
				var mov=cc.moveTo(0.6,cc.p(168,456));
				var move=cc.moveTo(0.6, cc.p(268,456));
				var seq=cc.sequence(move,cc.callFunc(function() {
					var p2=new cc.Sprite("#30ml.png");
					this.addChild(p2);
					p2.setPosition(cc.p(111,-40));
					var seq=cc.sequence(cc.delayTime(1.5),cc.fadeOut(0));
					p2.runAction(seq);
				}, this),cc.delayTime(2),mov,cc.callFunc(function() {
					this.getChildByTag(TAG_BLUE).setOpacity(255);
					hand.setVisible(false);
					part.setVisible(false);
					var show=new ShowTip("V1=20.0ml\nV3=30.0ml\nV2=V3-V1=10.0ml\n" +
							"由此得出结论，此混合碱溶液为NaOH和Na₂CO₃",cc.p(650,300));
				}, this),cc.delayTime(4),this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO9){
				if(this.getChildByTag(TAG_BLUE)!=null){
					this.getChildByTag(TAG_BLUE).removeFromParent();
				}				
				hand.setVisible(true);
				part.setVisible(true);
				
				var mov=cc.moveTo(0.6, cc.p(820,362));
				var rot=cc.rotateTo(0.6, 100);
				var rot1=cc.rotateTo(0.6, 0);
				var move=cc.moveTo(0.6, cc.p(640,230.4));
				var spa1=cc.spawn(move,rot);
				var seq=cc.sequence(mov,cc.callFunc(function() {
					var pic=new cc.Sprite("#0ml.png");
					pic.setPosition(cc.p(111,166));
					this.addChild(pic);
					var fad=cc.fadeOut(0);
					var seq=cc.sequence(cc.delayTime(2),fad);
					pic.runAction(seq);

					var line=new cc.Sprite("#beaker_line.png");
					pic.addChild(line);
					line.setPosition(cc.p(50,49));
					var seq1=cc.sequence(cc.delayTime(2),fad);
					line.runAction(seq1);
				}, this),cc.delayTime(2),spa1,cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(821,190),1);
					this.lineDown(cc.p(20,105));
				}, this),cc.callFunc(function() {
					beaker.lineUp(false,cc.p(0,2));
				}, this),cc.delayTime(1.7),rot1,this.callNext);
				this.runAction(seq); 
			}else if(action==Y1){
				var rot=cc.rotateTo(0.6, 100);
				var rot1=cc.rotateTo(0.6, 0);
				var move=cc.moveTo(0.6, cc.p(640,230.4));
				var spa1=cc.spawn(move,rot);
				var seq=cc.sequence(spa1,cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(821,190),1);
					this.lineDown(cc.p(20,105));
				}, this),cc.callFunc(function() {
					beaker.lineUp(false,cc.p(0,2));
				}, this),cc.delayTime(1.7),rot1,cc.callFunc(function() {

					var show=new ShowTip("同样方法，用自来水再重复清洗滴定管2次" ,cc.p(950,300));
				}, this),cc.delayTime(1),this.callNext);
				this.runAction(seq);
			}else if(action==Y2){
				var rot=cc.rotateTo(0.6, 100);
				var rot1=cc.rotateTo(0.6, 0);
				var move=cc.moveTo(0.6, cc.p(640,230.4));
				var spa1=cc.spawn(move,rot);
				var seq=cc.sequence(spa1,cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(821,190),1);
					this.lineDown(cc.p(20,105));
				}, this),cc.callFunc(function() {
					beaker.lineUp(false,cc.p(0,2));
				}, this),cc.delayTime(1.7),rot1,cc.callFunc(function() {
					var show=new ShowTip("同样方法，用蒸馏水再重复清洗滴定管2次" ,cc.p(950,300));
				}, this),cc.delayTime(1),this.callNext);
				this.runAction(seq);
			}else if(action==Y3){
				var rot=cc.rotateTo(0.6, 100);
				var rot1=cc.rotateTo(0.6, 0);
				var move=cc.moveTo(0.6, cc.p(640,230.4));
				var spa1=cc.spawn(move,rot);
				var seq=cc.sequence(spa1,cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(821,190),1);
					this.lineDown(cc.p(20,105));
				}, this),cc.callFunc(function() {
					beaker.lineUp(false,cc.p(0,2));
				}, this),cc.delayTime(1.7),rot1,cc.callFunc(function() {
					var showtip=new ShowTip("同样方法，用标准盐酸溶液再重复清洗滴定管2次" ,cc.p(970,280));
				}, this),cc.delayTime(1),this.callNext);
				this.runAction(seq);
			}
			break;
		case TAG_HUOSAI:
			if(action==ACTION_DO1){
				p.setSpriteFrame("ddg_huosai.png");
				var seq = cc.sequence(cc.delayTime(0.1),cc.callFunc(function(){
					p.setSpriteFrame("ddg_huosai2.png");
				this.getParent().clock.loadTip("#tool/tip1.png");
				this.getParent().clock.doTime(2);
			},this),func);
			p.runAction(seq);
			}else if(action==ACTION_DO2){
				p.setSpriteFrame("ddg_huosai1.png");
				var seq=cc.sequence(cc.callFunc(function(){
					this.getParent().water.flowDown(cc.p(830,190),1);
					this.lineDown(cc.p(24,145));
				}, this),cc.callFunc(function() {
					beaker.lineUp(false,cc.p(0,1));
				}, this),cc.delayTime(1.5),cc.callFunc(function() {
					p.setSpriteFrame("ddg_huosai2.png");
				},this),func);
				p.runAction(seq);
			}else if(action==ACTION_DO3){
				p.setSpriteFrame("ddg_huosai1.png");
				var seq=cc.sequence(cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(830,190),1);
					this.lineDown(cc.p(24,429));
					beaker.lineUp(false,cc.p(0,1));
				},this),cc.delayTime(2),cc.callFunc(function() {
					p.setSpriteFrame("ddg_huosai2.png");
				},this),cc.delayTime(0.5),func);
				p.runAction(seq);
//创建0刻度画面	
				var pic=new cc.Sprite("#0ml.png");
				pic.setPosition(cc.p(111,166));
				this.addChild(pic);
				var fad=cc.fadeOut(0);
				var seq=cc.sequence(cc.delayTime(2),fad);
				pic.runAction(seq);
				
				var line=new cc.Sprite("#beaker_line.png");
				pic.addChild(line);
				line.setPosition(cc.p(52,70));
				var move=cc.moveTo(1.5, cc.p(50,49));
				var seq1=cc.sequence(move,cc.delayTime(0.5),fad);
				line.runAction(seq1);
			}else if(action==ACTION_DO4){
				p.setSpriteFrame("ddg_huosai1.png");				
				
				var seq=cc.sequence(cc.callFunc(function() {
					this.lineDown(cc.p(24,360));
					this.schedule(this.loadPoint,0.3,2);			
				}, this),cc.callFunc(function() {	
					var mov1=cc.moveTo(0.1,cc.p(170,221));
					var mov2=cc.moveTo(0.1,cc.p(160,211));
					var mov3=cc.moveTo(0.1,cc.p(170,201));
					var mov4=cc.moveTo(0.1,cc.p(180,211));
					var seq=cc.sequence(mov1,mov2,mov3,mov4);
					var move=cc.moveTo(0.2, cc.p(170,211));
					var seq1=cc.sequence(cc.repeat(seq,3),move);
					this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).runAction(seq1);
					
					var fadeout=cc.fadeOut(3);										
					var zhui1=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_ZHUIXINGPING1);
					zhui1.runAction(fadeout);
					
					var fadein=cc.fadeIn(3);
					var zhui3=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_ZHUIXINGPING3);
					zhui3.runAction(fadein);
				}, this),cc.delayTime(1.5),cc.callFunc(function() {
					p.setSpriteFrame("ddg_huosai2.png");
				},this),cc.delayTime(1.5),func);
				p.runAction(seq);
			}else if(action==ACTION_DO5){
				p.setSpriteFrame("ddg_huosai1.png");
				var seq=cc.sequence(cc.callFunc(function() {
					this.lineDown(cc.p(24,220));
					this.schedule(this.loadPoint,0.5,3);				
				}, this),cc.callFunc(function() {
					var mov1=cc.moveTo(0.1,cc.p(170,221));
					var mov2=cc.moveTo(0.1,cc.p(160,211));
					var mov3=cc.moveTo(0.1,cc.p(170,201));
					var mov4=cc.moveTo(0.1,cc.p(180,211));
					var seq=cc.sequence(mov1,mov2,mov3,mov4);
					var move=cc.moveTo(0.2, cc.p(170,211));
					var seq1=cc.sequence(cc.repeat(seq,3),move);
					this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).runAction(seq1);
					
					var fadeout=cc.fadeOut(3);
					var zhui2=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_ZHUIXINGPING2);
					zhui2.runAction(fadeout);
					
					var fadein=cc.fadeIn(3);
					var zhui4=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_ZHUIXINGPING4);
					zhui4.runAction(fadein);
				}, this),cc.delayTime(1.5),cc.callFunc(function() {
					p.setSpriteFrame("ddg_huosai2.png");
				},this),cc.delayTime(1.5),func);
				p.runAction(seq);
			}else if(action==ACTION_DO6){
				this.loadHand();
				p.setSpriteFrame("ddg_huosai.png");
				var seq=cc.sequence(cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(830,190),1);
					this.lineDown(cc.p(21,103));
					beaker.lineUp(false,cc.p(0,5));
				},this),cc.delayTime(1.8),cc.callFunc(function() {
					p.setSpriteFrame("ddg_huosai2.png");
				}, this),cc.callFunc(function() {
					var move=cc.moveTo(0.6, cc.p(0,0));
					this.getChildByTag(TAG_DDG).runAction(move);
				}, this),func);
				p.runAction(seq);
			}else if(action==ACTION_DO7){
				p.setSpriteFrame("ddg_huosai1.png");
				var seq=cc.sequence(cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(830,190),1);
					this.lineDown(cc.p(24,429));
				},this),cc.delayTime(2),cc.callFunc(function() {
					p.setSpriteFrame("ddg_huosai2.png");
				},this),func);
				p.runAction(seq);
//				创建0刻度画面	
				var pic=new cc.Sprite("#0ml.png");
				pic.setPosition(cc.p(111,166));
				this.addChild(pic);
				var fad=cc.fadeOut(0);
				var seq=cc.sequence(cc.delayTime(1.7),fad);
				pic.runAction(seq);

				var line=new cc.Sprite("#beaker_line.png");
				pic.addChild(line);
				line.setPosition(cc.p(50,55));
				var move=cc.moveTo(1.7, cc.p(50,49));
				var seq1=cc.sequence(move,fad);
				line.runAction(seq1);
			}
			break;
		default:
			break;
		}
	},
	actionDone:function(p){
		var action=gg.flow.flow.action;
		var beaker=this.getParent().getChildByTag(TAG_BEAKER);
		switch(p.getTag()){
		case TAG_DDG:		
				gg.flow.next();
			break;
		case TAG_HUOSAI:
				gg.flow.next();
			break;
		default:
			break;
		}
	},
	onExit:function(){
		this._super();
		this.callNext.release();
	}
});